package com.tbit.main.service.impl;

import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.collection.ListUtil;
import cn.hutool.core.text.StrPool;
import cn.hutool.core.util.StrUtil;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONException;
import com.alibaba.fastjson.JSONObject;
import com.tbit.common.constant.CommonConstant;
import com.tbit.common.constant.OperationPlatform;
import com.tbit.common.entity.MachineOpLog;
import com.tbit.main.constant.*;
import com.tbit.main.controller.interceptor.LoginUserContextHolder;
import com.tbit.main.dao.log.MoveLogDao;
import com.tbit.main.exception.BaseException;
import com.tbit.main.h2.pojo.ParkPoint;
import com.tbit.main.pojo.*;
import com.tbit.main.pojo.bo.CommonControlParamBO;
import com.tbit.main.pojo.bo.TerControlBO;
import com.tbit.main.service.*;
import com.tbit.main.util.DateTimeUtil;
import com.tbit.main.util.GeoUtil;
import com.tbit.main.util.LogUtil;
import com.tbit.main.util.StringUtil;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.collections4.ListUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.serializer.SerializationException;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.time.temporal.ChronoUnit;
import java.util.*;
import java.util.function.Function;
import java.util.stream.Collectors;

import static com.tbit.main.constant.WorkOrderConstant.isValid;

/**
 * 挪车记录
 *
 * @author Leon
 * 2019年11月12日 下午4:47:36
 */
@Slf4j
@Service("moveLogService")
public class MoveLogServiceImpl implements MoveLogService {
    @Autowired
    private MoveLogDao moveLogDao;
    @Autowired
    private RedisService redisService;
    @Autowired
    private ParkPointService parkPointService;
    @Autowired
    private MachineService machineService;
    @Autowired
    private MachineStatusService machineStatusService;
    @Autowired
    private TerControlService terControlService;
    @Autowired
    private AccountUserService accountUserService;
    @Autowired
    private MoveConfigService moveConfigService;
    @Autowired
    private HistoryService historyService;
    @Autowired
    private AccountConfigService accountConfigService;
    @Autowired
    private MachineOccupyService machineOccupyService;
    @Autowired
    private CalibrateService calibrateService;
    @Autowired
    private WorkOrderService workOrderService;
    @Autowired
    private GeoreMachineService georeMachineService;
    @Autowired
    private GeoreGionService georeGionService;
    @Autowired
    private WorkOrderFinishingService workOrderFinishingService;
    @Autowired
    private DataService dataService;
    @Autowired
    private RoleService roleService;
    @Autowired
    private MachineAbnormalService machineAbnormalService;
    @Autowired
    private VerticalParkLogService verticalParkLogService;
    @Autowired
    private MachineFunctionService machineFunctionService;
    @Autowired
    private MachineOpLogService machineOpLogService;
    @Autowired
    private MovePerformanceService movePerformanceService;
    @Autowired
    private RideLogService rideLogService;

    @Override
    public Integer insert(MoveLog moveLog) {
        Integer result = moveLogDao.insert(moveLog);

        AccountUser accountUser = LoginUserContextHolder.getLoginUser();

        // 插入车辆操作日志
        machineOpLogService.insertSingle(MachineOpLog.builder()
                .accountId(moveLog.getAccountId())
                .machineId(moveLog.getMachineId())
                .machineNO(moveLog.getMachineNO())
                .userCode(moveLog.getUserCode())
                .operation("挪车")
                .opUser(accountUser.getName())
                .opUserPhone(accountUser.getPhone())
                .opPlatform(OperationPlatform.MAINTAIN.code)
                .result(true)
                .opTime(LocalDateTime.now())
                .build()
        );
        // 插入挪车绩效
        movePerformanceService.calculateAndInsertPerformance(moveLog);

        return result;
    }

    @Override
    public List<MoveLogSta> groupByTime(Integer agentId, Integer userType, Integer usermainId, Boolean isValid, String startTime, String endTime,
                                        List<Integer> regionId, Integer machineType) {
        List<MoveLogSta> mlses;

        /**查询代理商运维账号*/
        List<Integer> accountUserIds = new ArrayList<>();
        /**判断当前账号是不是运维人员*/
        if (roleService.getRoleCode(userType).equals(1)) {
            accountUserIds.add(usermainId);
        }

        Map<String, Object> params = new HashMap<>();
        params.put(DaoParamConstant.accountId, agentId);
        params.put("userMainIds", StringUtil.getListString(accountUserIds));
        params.put("isValid", isValid);
        params.put(DaoParamConstant.startTime, startTime);
        params.put(DaoParamConstant.endTime, endTime);
        if (CollUtil.isEmpty(regionId)) {
            params.put("exist", "'exist'");
            regionId = georeGionService.getByAccountUserId(usermainId);
        } else {
            params.put("exist", null);
        }
        params.put("regionId", StringUtil.getListString(regionId));
        params.put("machineType", machineType);
        mlses = moveLogDao.groupByTime(params);

        List<Integer> userMainIds = mlses.stream().map(MoveLogSta::getUserMainId).collect(Collectors.toList());
        Map<Integer, AccountUser> accountUserMap = accountUserService.getByIds(userMainIds)
                .stream().collect(Collectors.toMap(AccountUser::getAccountUserId, Function.identity()));

        List<MoveLogSta> mlsefilterss = new ArrayList<>();
        for (MoveLogSta mls : mlses) {
            Optional.ofNullable(accountUserMap.get(mls.getUserMainId()))
                    .ifPresent(au -> {
                        mls.setName(au.getName());
                        mls.setPhone(au.getPhone());
                        mls.setDelFlag(au.getDelFlag());
                        mlsefilterss.add(mls);
                    });
        }

        return mlsefilterss;
    }

    @Override
    public List<MoveLog> getByTime(Integer accountId, Integer userMainId, Boolean isValid, String startTime,
                                   String endTime, String userCode, List<Integer> regionId, Integer machineType) {
        Map<String, Object> params = new HashMap<>();
        params.put(DaoParamConstant.accountId, accountId);
        params.put("userMainId", userMainId);
        params.put("isValid", isValid);
        params.put(DaoParamConstant.startTime, startTime);
        params.put(DaoParamConstant.endTime, endTime);
        if (CollUtil.isEmpty(regionId)) {
            params.put("exist", "'exist'");
            regionId = georeGionService.getByAccountUserId(userMainId);
        } else {
            params.put("exist", null);
        }
        params.put("regionId", StringUtil.getListString(regionId));
        params.put("machineType", machineType);
        params.put("userCode", userCode);
        return moveLogDao.getByTime(params);
    }

    @Override
    public MoveLog getById(Integer moveLogId) {
        return moveLogDao.getById(moveLogId);
    }

    @Override
    public MoveLog move(AccountUser accountUser, String machineNO, Integer parkPointId, Double lon, Double lat, Integer mapType) {
        MoveLog moveLog = null;

        Machine machine = machineService.getByMachineNO(machineNO);
        if (machine == null) {
            throw new BaseException("Machine.notExist");
        }
        MachineStatus machineStatus = machineStatusService.getByMachineId(machine.getMachineId());
        /**redis获取数据*/
        String moveLogString = null;
        try {
            moveLogString = redisService.get(RedisConstant.REDIS_TER_BIKE_MOVE + machineNO);
        } catch (SerializationException e) {
            redisService.del(RedisConstant.REDIS_TER_BIKE_MOVE + machineNO);
        }


        /**批量获取redis数据，人员*/
        String userId = RedisConstant.REDIS_BATCH_MOVE + accountUser.getAccountUserId();
        /**批量获取redis数据，区域*/
        String userIdMove = RedisConstant.REDIS_BATCH_MOVE_AREA + machine.getAccountId();

        String nowTime = DateTimeUtil.getNowTime();

        if (moveLogString == null) {


            Integer value = dataService.getRoleConfig(accountUser.getAccountUserType() + RoleConfigConstant.MAIN_LOCK_VEHICLE);
            if (value != null && value.equals(1)) {
                /**获取运营区域配置*/
                AccountConfig accountConfig = accountConfigService.getByAccountId(accountUser.getAccountId());
                /**运维占用最大数判断*/
                if (accountConfig != null) {
                    if (accountConfig.getOccupyMax() != null && !accountConfig.getOccupyMax().equals(0)) {
                        Integer occupy = machineOccupyService.getByAccountUserId(accountUser.getAccountUserId());
                        if (occupy >= accountConfig.getOccupyMax()) {
                            throw new BaseException("Machine.occupyMax.exist");
                        }
                    }
                }
            }

            /**记录挪车记录*/
            MoveLog ml = new MoveLog();
            ml.setAccountId(machine.getAccountId());
            ml.setUserMainId(accountUser.getAccountUserId());
            ml.setMachineId(machine.getMachineId());
            ml.setUserCode(machine.getUserCode());
            ml.setMachineNO(machine.getMachineNO());
            ml.setStartLon(machineStatus.getLon());
            ml.setStartLat(machineStatus.getLat());
            ml.setStartTime(DateTimeUtil.getNowTime());
            ml.setUserIdStartLon(lon);
            ml.setUserIdStartLat(lat);
            ml.setMachineType(machine.getMachineType());

            /** 判断是否在区域内 */
            List<Point> geo = dataService.getGeo(ml.getAccountId());
            Boolean isInArea = GeoUtil.IsPtInPoly(new Point(machineStatus.getLon(), machineStatus.getLat()), geo);
            if (!isInArea) {
                ml.setRemark("超区");
                movePerformanceService.cacheMoveType(machine.getMachineId(), 2);
            }

            List<MachineAbnormal> abnormals = machineAbnormalService.getByMachineId(machine.getMachineId());
            if (abnormals != null && !abnormals.isEmpty()) {
                for (MachineAbnormal machineAbnormal : abnormals) {
                    if (machineAbnormal.getAbnormalType().equals(MachineAbnormalConstant.MACHINE_ABNORMAL_ZW)) {
                        ml.setRemark("站外");
                        movePerformanceService.cacheMoveType(machine.getMachineId(), 1);
                    }
                }
            }

            /**
             * 判断分区
             */
            GeoreMachine georeMachine = georeMachineService.getByMachineId(machine.getMachineId());
            if (georeMachine != null) {
                ml.setRegionId(georeMachine.getRegionId());
            }


            /**判断是否是禁停区*/
            AccountConfig ac = dataService.getAccountConfig(machine.getAccountId());
            if (ac != null && ac.getReturnModel() == 1) {
            } else {
                /** 重新判断站点 */
                MachineStatus mahcineStatus = dataService.getMachineStatus(machine.getMachineId());
                if (mahcineStatus != null) {
                    ParkPoint parkPointNEW = parkPointService.checkInParkPointNew(machine.getAccountId(), new Point(mahcineStatus.getLon(), mahcineStatus.getLat()), 50, null);
                    if (parkPointNEW != null) {
                        machineService.put(new ParkMachine(parkPointNEW.getParkPointId(), machine.getMachineId(), parkPointNEW.getInside()));
                    }
                }
            }

            ParkPoint parkMachine = parkPointService.getByMachineId(machine.getMachineId());
            if (parkMachine != null) {
                ml.setOldParkPointId(parkMachine.getParkPointId());
                ml.setOldParkPointName(parkMachine.getName());
                redisService.add(RedisConstant.REDIS_TER_BIKE_DISPATCHANDMOVE + machine.getMachineId(), parkMachine.getParkPointId() + "", 3600 * 3);
            }
            //挪车前置条件判断
            ml.setRemark(this.movePreconditionCheck(machine,ml));

            redisService.add(RedisConstant.REDIS_TER_BIKE_MOVE + machineNO, JSONObject.toJSONString(ml), 3600 * 3);
            // 运维绩效-记录当前车辆异常
            movePerformanceService.cacheAbnormal(machine.getMachineId());

            // 排除小红羚单车指定区域的开锁业务
            if ((machine.getMachineType().equals(MachineTypeConstant.BIKE) && machineFunctionService.checkIsSendControl(machine.getMachineId()))
                    || machine.getMachineType().equals(MachineTypeConstant.ELECTRIC_BIKE)) {
                /**开锁*/
                TerControlBO terControl1 = new TerControlBO(ControlType.MACHINE_CONTROL_UNLOCK, "挪车自动开锁");
                /**头盔锁发送强制开锁指令*/
                TerControlBO terControl2 = new TerControlBO(ControlType.MACHINE_CONTROL_COERCE_LOCK, "挪车自动开锁-强制开锁");
                terControlService.batchControl(machine, ListUtil.of(terControl1, terControl2));
            }

            /**批量获取redis数据，人员*/
            List<String> userCode = new LinkedList<>();
            try {
                userCode = redisService.getList(userId);
            } catch (SerializationException e) {
                redisService.del(userId);
            }

            if (userCode == null || !userCode.contains(machine.getUserCode())) {
                /**批量添加到redis中*/
                redisService.andToList(userId, machine.getUserCode());
            }
            /**批量获取redis数据，人员*/
            List<String> userCodeMove = new LinkedList<>();
            try {
                userCodeMove = redisService.getList(userIdMove);
            } catch (SerializationException e) {
                redisService.del(userIdMove);
            }
            if (userCodeMove == null || !userCodeMove.contains(machine.getUserCode())) {
                /**批量添加到redis中*/
                redisService.andToList(userIdMove, machine.getUserCode());
            }

            /**记录运维事件轨迹*/
            try {
                TerPosition terPosition = new TerPosition();
                terPosition.setMachineNO(accountUser.getPhone());
                terPosition.setLat(lat);
                terPosition.setLon(lon);
                terPosition.setDt(DateTimeUtil.getNowTime());
                terPosition.setExData(HistoryExData.UW + "=" + HistoryExData.NC + ";");
                calibrateService.calTerPosition(terPosition, mapType, SysConstant.ORIGINAL);
                historyService.insert(terPosition);
            } catch (Exception e) {
                log.error("挪车记录运维事件轨迹异常 车辆id-{} 设备编号-{}",machine.getMachineId(),machineNO, e);
            }

            /**记录垂直停车记录*/
            verticalParkLogService.updateEnable(machine.getMachineNO());

            redisService.add(RedisConstant.REDIS_TER_BIKE_MOVE_USER_CODE + machine.getUserCode(), machineNO, 3600 * 3);
        } else {

            String dateTime = DateTimeUtil.getMinsAgo(5);
            try {
                moveLog = JSONObject.parseObject(moveLogString, MoveLog.class);
            } catch (JSONException e) {
                redisService.del(RedisConstant.REDIS_TER_BIKE_MOVE + machineNO);
            }

            if (parkPointId != null) {
                /**查询站点*/
                ParkPoint parkPoint = parkPointService.getByParkPointId(parkPointId);
                if (parkPoint == null) {
                    throw new BaseException("ParkPoint.notExist");
                }
                moveLog.setEndTime(DateTimeUtil.getNowTime());
                moveLog.setEndLon(machineStatus.getLon());
                moveLog.setEndLat(machineStatus.getLat());
                moveLog.setParkPointId(parkPoint.getParkPointId());
                moveLog.setParkPointName(parkPoint.getName());
                moveLog.setIsValid(Objects.nonNull(moveLog.getIsValid()) ? moveLog.getIsValid() : true);
                moveLog.setUserIdEndLon(lon);
                moveLog.setUserIdEndLat(lat);
                moveLog.setMapType(mapType);

                /**判断是否有效挪车*/
                /**加载挪车配置*/
                MoveConfig moveConfig = moveConfigService.getByAccountId(machine.getAccountId());

                boolean dispatchJudge = true;
                /**投放车辆*/
                Integer inside = null;
                if (machineStatus != null) {
                    //检查是否在站内
                    inside = this.checkInPark(parkPointId,machineStatus,moveConfig);
                }
                if (moveConfig != null) {
                    //检查挪车配置，挪车是否生效
                    dispatchJudge = this.checkMoveConfig(moveConfig,moveLog,machine,parkPointId,dateTime,mapType,inside);
                    /**是否是同一个站点*/
                    if (dispatchJudge) {
                        this.addMoveLog(moveLog,moveConfig,machine,accountUser,nowTime);
                    }

                    /**修改最后借出时间*/
                    machineService.updateLastBorrowTime(machine.getMachineId());

                    Integer i = machineService.parkMachineInside(machine.getMachineId(), parkPoint.getParkPointId(), inside);
                    if (i == 0) {
                        machineService.put(new ParkMachine(parkPoint.getParkPointId(), machine.getMachineId(), inside));
                    }
                    /**批量删除到redis中，人员*/
                    redisService.delToList(userId, machine.getUserCode());
                    /**批量删除到redis中，区域*/
                    redisService.delToList(userIdMove, machine.getUserCode());

                    redisService.del(RedisConstant.REDIS_TER_BIKE_MOVE_USER_CODE + machine.getUserCode());

                    /**自动上锁*/
                    moveLock(machine, "挪车完成自动上锁");

                    //把之前的挪车记录变成无效
                    this.checkMachineLastMove(machine.getMachineNO(),moveLog.getMoveLogId(),moveConfig,nowTime);
                    //更新缓存
                    if (!dispatchJudge){
                        redisService.add(RedisConstant.REDIS_TER_BIKE_MOVE + machine.getMachineNO(), JSONObject.toJSONString(moveLog), 3600 * 3);
                    }
                }
            }
        }
        return moveLog;
    }

    @Override
    public String endWork(AccountUser accountUser, Machine machine, MoveLog moveLog, Integer state) {
        /**是否存在工单信息*/
        List<WorkOrderFinishing> workOrderFinishingList = workOrderFinishingService.getByWorkMachineIdState(machine.getMachineId(), WorkOrderConstant.state_LQ);
        String workOrderId = null;
        for (WorkOrderFinishing workOrderFinishing : workOrderFinishingList) {
            accountUser = Optional.ofNullable(accountUser).orElseGet(AccountUser::new);
            // 挪车完成后删除待办的调度工单
            if (workOrderFinishing.getWorkType().equals(WorkOrderConstant.workType_DD)) {
                workOrderService.del(workOrderFinishing.getWorkOrderId());
                workOrderFinishingService.del(workOrderFinishing.getWorkOrderId());
                log.info("挪车工单完成删除调度工单：" + workOrderFinishing.getWorkOrderId());
            }
            // 结束挪车工单
            if (workOrderFinishing.getWorkType().equals(WorkOrderConstant.workType_NC)) {
//                workOrderService.endWork(WorkOrderConstant.workType_NC, accountUser, machine.getMachineId(), moveLog.getMoveLogId(), moveLog.getIsValid() ? 1 : 0, null, state);
                // 更新已完成工单
                WorkOrder workOrder = new WorkOrder();
                workOrder.setWorkOrderId(workOrderId);
                workOrder.setGetUserId(accountUser.getAccountUserId());
                workOrder.setGetUserName(accountUser.getName());
                workOrder.setBusinessNO(moveLog.getMoveLogId());
                workOrder.setState(state);
                workOrder.setFinishTime(DateTimeUtil.getNowTime());
                workOrder.setIsValid(moveLog.getIsValid() ? WorkOrderConstant.valid : isValid);
                workOrder.setRemark(moveLog.getRemark());
                workOrderService.update(workOrder);
                log.info("挪车工单完成：" + workOrderFinishing.getWorkOrderId());
                workOrderId = workOrderFinishing.getWorkOrderId();
            }
        }
        return workOrderId;
    }

    @Override
    public Integer groupByAccountIdTime(Integer accountId, Boolean isVaild, String startTime, String endTime) {
        Map<String, Object> params = new HashMap<String, Object>();
        params.put(DaoParamConstant.accountId, accountId);
        params.put("isValid", isVaild);
        params.put(DaoParamConstant.startTime, startTime);
        params.put(DaoParamConstant.endTime, endTime);
        return moveLogDao.groupByAccountIdTime(params);
    }

    @Override
    public Integer groupByRegionIdTime(Integer regionId, Boolean isVaild, String startTime, String endTime) {
        Map<String, Object> params = new HashMap<String, Object>();
        params.put("regionId", regionId);
        params.put("isValid", isVaild);
        params.put(DaoParamConstant.startTime, startTime);
        params.put(DaoParamConstant.endTime, endTime);
        return moveLogDao.groupByRegionIdTime(params);
    }

    @Override
    public List<Map<String, Object>> getGroupByDay(Integer accountId, String statDate, String endDate) {
        Map<String, Object> params = new HashMap<String, Object>();
        params.put(DaoParamConstant.accountId, accountId);
        params.put("statDate", statDate);
        params.put("endDate", endDate);

        return moveLogDao.getGroupByDay(params);
    }

    @Override
    public void moveBatch(AccountUser accountUser, List<String> userCodes, Integer parkPointId, Double lon, Double lat, Integer mapType) {

        userCodes = userCodes.stream().distinct().collect(Collectors.toList());

        MoveLog moveLog = null;
        String nowTime = DateTimeUtil.getNowTime();
        List<Machine> machineList = machineService.getByUserCodes(userCodes);
        String dateTime = DateTimeUtil.getMinsAgo(5);
        for (Machine machine : machineList) {
            boolean dispatchJudge = true;
            MachineStatus machineStatus = machineStatusService.getByMachineId(machine.getMachineId());

            /**redis获取数据*/
            String moveLogString = redisService.get(RedisConstant.REDIS_TER_BIKE_MOVE + machine.getMachineNO());
            if (moveLogString != null) {
                try {
                    moveLog = JSONObject.parseObject(moveLogString, MoveLog.class);
                } catch (JSONException e) {
                    redisService.del(RedisConstant.REDIS_TER_BIKE_MOVE + machine.getMachineNO());
                }

                /**查询站点*/
                ParkPoint parkPoint = parkPointService.getByParkPointId(parkPointId);
                if (parkPoint == null) {
                    throw new BaseException("ParkPoint.notExist");
                }

                moveLog.setEndTime(DateTimeUtil.getNowTime());
                moveLog.setEndLon(machineStatus.getLon());
                moveLog.setEndLat(machineStatus.getLat());
                moveLog.setParkPointId(parkPoint.getParkPointId());
                moveLog.setParkPointName(parkPoint.getName());
                moveLog.setIsValid(Objects.nonNull(moveLog.getIsValid()) ? moveLog.getIsValid() : true);
                moveLog.setUserIdEndLon(lon);
                moveLog.setUserIdEndLat(lat);

                /**判断是否有效挪车*/
                /**加载挪车配置*/
                Integer inside = null;
                MoveConfig moveConfig = moveConfigService.getByAccountId(machine.getAccountId());
                if (machineStatus != null) {
                    inside = this.checkInPark(parkPointId,machineStatus,moveConfig);
                }
                if (moveConfig != null) {
                    //检查挪车配置，挪车是否生效
                   dispatchJudge = this.checkMoveConfig(moveConfig,moveLog,machine,parkPointId,dateTime,mapType,inside);
                }
                /**
                 * 判断分区
                 */
                GeoreMachine georeMachine = georeMachineService.getByMachineId(machine.getMachineId());
                if (georeMachine != null) {
                    moveLog.setRegionId(georeMachine.getRegionId());
                }

                if (dispatchJudge) {
                    this.addMoveLog(moveLog,moveConfig,machine,accountUser,nowTime);
                }

                /**修改最后借出时间*/
                if (Objects.isNull(moveConfig) || Objects.equals(moveConfig.getClearLastBorrowTime(), 1)) {
                    machineService.updateLastBorrowTime(machine.getMachineId());
                }

                /**投放车辆*/
                try {
                    Integer i = machineService.parkMachineInside(machine.getMachineId(), parkPoint.getParkPointId(), inside);
                    if (i == 0) {
                        machineService.put(new ParkMachine(parkPoint.getParkPointId(), machine.getMachineId(), inside));
                    }
                } catch (Exception e) {
                    LogUtil.error(e.getMessage(), e);
                }


                /**批量删除到redis中，人员*/
                String userId = RedisConstant.REDIS_BATCH_MOVE + accountUser.getAccountUserId();
                redisService.delToList(userId, machine.getUserCode());
                /**批量删除到redis中，区域*/
               
                String userIdMove = RedisConstant.REDIS_BATCH_MOVE_AREA + machine.getAccountId();
                redisService.delToList(userIdMove, machine.getUserCode());

               
                /**自动上锁*/
                moveLock(machine, "挪车完成自动上锁");

                //把之前的挪车记录变成无效
                this.checkMachineLastMove(machine.getMachineNO(),moveLog.getMoveLogId(),moveConfig,nowTime);
                //更新缓存
                if (!dispatchJudge){
                    redisService.add(RedisConstant.REDIS_TER_BIKE_MOVE + machine.getMachineNO(), JSONObject.toJSONString(moveLog), 3600 * 3);
                }
            } else {
                /**删除已被他人调度的车辆，人员*/
                String userId = RedisConstant.REDIS_BATCH_MOVE + accountUser.getAccountUserId();
                redisService.delToList(userId, machine.getUserCode());

                /**删除已被他人调度的车辆，区域*/
             
                String userIdMove = RedisConstant.REDIS_BATCH_MOVE_AREA + machine.getAccountId();
                redisService.delToList(userIdMove, machine.getUserCode());
            }
            redisService.del(RedisConstant.REDIS_TER_BIKE_MOVE_USER_CODE + machine.getUserCode());
        }
    }

    @Override
    public void moveLock(Machine machine, String remark) {

        // 排除新版单车不触发开锁业务
        if ((machine.getMachineType().equals(MachineTypeConstant.BIKE) && machineFunctionService.checkIsSendControl(machine.getMachineId()))
                || machine.getMachineType().equals(MachineTypeConstant.ELECTRIC_BIKE)) {
            /**自动上锁*/
            String serNO = UUID.randomUUID().toString();
            terControlService.commonControl(new CommonControlParamBO(serNO, machine, ControlType.MACHINE_CONTROL_LOCK, remark));
        }
    }

    @Override
    public List<MoveLog> getMoveLogIds(List<Integer> moveLogIds, Integer mapType) {
        List<MoveLog> move = new LinkedList<>();
        List<List<Integer>> moveIds = ListUtils.partition(moveLogIds, 900);
        for (List<Integer> moveId : moveIds) {
            move.addAll(moveLogDao.getMoveLogIds(StringUtil.getListString(moveId)));
        }

        if (mapType == null) {
            mapType = SysConstant.GOOGLE;
        }
        for (MoveLog moveLog : move) {
            calibrateService.calMoveLog(moveLog, MapConstant.MAP_ORI, mapType);
            /**计算挪车距离*/
            if (moveLog.getEndLon() != null && moveLog.getEndLat() != null) {
                Integer distance = historyService.getMileageByMachineNOAndTime(moveLog.getMachineNO(), moveLog.getStartTime(), moveLog.getEndTime());
                moveLog.setDistance(distance);
            }
        }

        return move;
    }

    @Override
    public void delCache(String userCode) {
        AccountUser loginUser = LoginUserContextHolder.getLoginUser();
        String moveUserCodeKey = RedisConstant.REDIS_TER_BIKE_MOVE_USER_CODE + userCode;
        String machineNO = redisService.get(moveUserCodeKey);

        String dispatchLogString = redisService.get(RedisConstant.REDIS_TER_BIKE_MOVE + machineNO);
        Integer accountUserId = loginUser.getAccountUserId();
        Integer accountId = loginUser.getAccountId();
        if (StrUtil.isNotBlank(dispatchLogString)) {
            DispatchLog dispatchLogCache = JSONObject.parseObject(dispatchLogString, DispatchLog.class);
            accountUserId = dispatchLogCache.getUserMainId();
            accountId = dispatchLogCache.getAccountId();
        }

        /**删除redis记录*/
        redisService.del(RedisConstant.REDIS_TER_BIKE_MOVE + machineNO);

        /**批量删除到redis中，人员*/
        redisService.delToList(RedisConstant.REDIS_BATCH_MOVE + accountUserId, userCode);
        /**批量删除到redis中，区域*/
        redisService.delToList(RedisConstant.REDIS_BATCH_MOVE_AREA + accountId, userCode);

        redisService.del(moveUserCodeKey);
    }

    @Override
    public void batchDelCache(List<String> userCodes) {
        userCodes.forEach(this::delCache);
    }

    @Override
    public void audit(Integer moveId, boolean isValid, String remark) {
        MoveLog moveLog = new MoveLog();
        moveLog.setMoveLogId(moveId);
        moveLog.setIsValid(isValid);
        moveLog.setRemark(remark);
        moveLogDao.updateCheckNull(moveLog);
    }

    /**
     * @description: 检查挪车配置，挪车是否生效
     * @author: mo.shanyong
     * @date: 2025/5/15 17:29
     * @param: moveConfig
     * @param: moveLog
     * @param: machine 车辆
     * @param: parkPointId 站点id
     * @param: dateTime
     * @param: mapType
     * @param: inside 是否在站内 1-在站内；0-不在站内
     * @return: boolean
     */
    private boolean checkMoveConfig(MoveConfig moveConfig,MoveLog moveLog,Machine machine,
                                    Integer parkPointId,String dateTime,Integer mapType,Integer inside){
        Integer distance = 0;
        Integer machineIdDt = machineStatusService.getByBatDtId(machine.getMachineId(), dateTime);
        try {
            if (machineIdDt != null) {
                distance = historyService.getMileageByMachineNOAndTime(machine.getMachineNO(), moveLog.getStartTime(), moveLog.getEndTime());
            } else {
                Point pointS = new Point(moveLog.getUserIdStartLon(), moveLog.getUserIdStartLat());
                Point pointE = new Point(moveLog.getUserIdEndLon(), moveLog.getUserIdEndLat());
                pointS = calibrateService.commonCalibrate(pointS, mapType, SysConstant.ORIGINAL);
                pointE = calibrateService.commonCalibrate(pointE, mapType, SysConstant.ORIGINAL);
                distance = (int) GeoUtil.getDistance(pointS, pointE);
            }
        } catch (Exception e) {
            log.error(e.getMessage(), e);
            distance = 0;
        }
        distance = Objects.isNull(distance) ? 0 : distance;
        moveLog.setDistance(distance);
        //前置校验
        boolean dispatchJudge = true;
        if (!moveLog.getIsValid()){//如果不满足前置条件，则直接无效
            return dispatchJudge;
        }
        StringBuilder remark = new StringBuilder(moveLog.getRemark() == null ? "" : moveLog.getRemark()).append("【有效性条件】");
        /**是否是同一个站点*/
        remark.append("挪车后是否在同一个站点：");
        if (moveConfig.getSameParkPoint().equals(0)) {
            String parkPointIdRedis = redisService.get(RedisConstant.REDIS_TER_BIKE_DISPATCHANDMOVE + machine.getMachineId());
            if (parkPointIdRedis != null && !parkPointIdRedis.equals("") && parkPointId.equals(Integer.valueOf(parkPointIdRedis))) {
                moveLog.setIsValid(false);
//                dispatchJudge = false;
                remark.append("否").append("(无效)；");
            } else {
                moveLog.setIsValid(moveLog.getIsValid());
                remark.append("是").append("(有效)；");
            }

            log.info(moveLog.getMachineId() + ",配置站点：" + moveConfig.getSameParkPoint() + ",老站点：" + parkPointIdRedis + ",新站点：" + parkPointId);
        }else {
            remark.append("允许同一站点；");
        }

        remark.append("挪车后是否在站点：");
        /**挪车后是否在站点内*/
        if (Objects.equals(moveConfig.getMoveAfterInPark(), Constant.SWITCH_OPEN)){
            moveLog.setIsValid(Objects.equals(inside,1) ? moveLog.getIsValid() : false);
            remark.append(Objects.equals(inside,1) ? "站点内(有效)；" : "站点外(无效)；");
        }
        else {
            remark.append("关闭；");
        }
        remark.append("挪车距离：");
        //挪车距离
        if (Objects.nonNull(moveConfig.getMoveDistance())) {
            remark.append("配置：").append(moveConfig.getMoveDistance()).append("米，");
            remark.append("实际：").append(distance).append("米");
            if (distance < moveConfig.getMoveDistance()) {
                moveLog.setIsValid(false);
                dispatchJudge = false;
                /**添加到redismap*/
                redisService.set(RedisConstant.REDIS_TER_BIKE_MOVE_DISTANCE_CHANGE_MAP, machine.getMachineNO(), String.valueOf(System.currentTimeMillis()));
                redisService.add(RedisConstant.REDIS_TER_BIKE_MOVE + machine.getMachineNO(), JSONObject.toJSONString(moveLog), 3600 * 3);
                remark.append("(无效)");
                log.info("挪车增加距离缓存" + machine.getUserCode());
            } else {
                moveLog.setIsValid(moveLog.getIsValid());
                remark.append("(有效)");
            }

            log.info(moveLog.getMachineId() + ",配置距离：" + moveConfig.getMoveDistance() + ",实际距离：" + distance);
        }else {
            remark.append("关闭");
        }
        //产生订单
//        dispatchJudge = dispatchJudge ? (Objects.isNull(moveConfig.getRideTime()) || moveConfig.getRideTime() <= 0) : dispatchJudge;
        if(dispatchJudge){
            moveLog.setRemark(remark.toString());
        }
        log.info("挪车结果校验，dispatchJudge：{}，remark:{}",dispatchJudge,remark.toString());
        return dispatchJudge;
    }
    /**
     * @description: 判断挪车前置条件
     * @author: mo.shanyong
     * @date: 2025/5/16 10:30
     * @param: moveConfig
     * @param: machine
     * @param: moveLog
     * @return: java.lang.String
     */
    private String movePreconditionCheck(Machine machine, MoveLog moveLog) {
        MoveConfig moveConfig = moveConfigService.getByAccountId(machine.getAccountId());
        if (StringUtils.isBlank(moveConfig.getCheckedCondition())) {
            return "";
        }
        log.info("挪车时间" + moveLog.getStartTime() + "系统配置:" + moveConfig);
        List<String> checkedCondition = Arrays.stream(moveConfig.getCheckedCondition().split(","))
                .collect(Collectors.toList());
        if (checkedCondition.isEmpty()) {
            return "";
        }
        String nowTime = DateTimeUtil.getNowTime();
        boolean matchOne = moveConfig.matchOne();
        StringBuilder remark = new StringBuilder(moveLog.getUserCode() + (matchOne ? ";[前置条件]满足任一：" : ";[前置条件]满足所有："));
        int failedConditionsCount = 0;
        // 配置时长校验
        /**
         * 挪车前是否在站外/超区-0；上次挪车后产生有效订单-1；上次挪车后骑行xx米-2；上次挪车后经过xx分钟-3
         *
         * */
        // 挪车前是否在站外/超区
        remark.append("挪车前是否在站外/超区：");
        if (checkedCondition.contains("0")) {
            List<MachineAbnormal> machineAbnormalList = machineAbnormalService.getByMachineId(machine.getMachineId());
            //区域外
            MachineAbnormal ccqyAbnormal = CollectionUtils.isNotEmpty(machineAbnormalList) ? machineAbnormalList.stream().filter(machineAbnormal -> {
                return Objects.equals(machineAbnormal.getAbnormalType(), MachineAbnormalConstant.MACHINE_ABNORMAL_CCQY);
            }).findFirst().orElse(null) : null;
            //站外
            MachineAbnormal zwAbnormal = CollectionUtils.isNotEmpty(machineAbnormalList) ? machineAbnormalList.stream().filter(machineAbnormal -> {
                return Objects.equals(machineAbnormal.getAbnormalType(), MachineAbnormalConstant.MACHINE_ABNORMAL_ZW);
            }).findFirst().orElse(null) : null;
            boolean abnormal = Objects.isNull(ccqyAbnormal) && Objects.isNull(zwAbnormal);
            if (abnormal) {
                failedConditionsCount++;
            }
            String str = abnormal ? "无效；" : (Objects.isNull(zwAbnormal) ? "区域外" : "站外");
            remark.append(str)
                    .append(abnormal ? "" : "(有效)；");
        }else {
            remark.append("关闭；");
        }

        List<MoveLog> moveLogs = this.getByMachineIdTime(machine.getMachineId(), null);
        List<RideLog> rideLogs;
        if (CollectionUtils.isNotEmpty(moveLogs)) {
            rideLogs = rideLogService.getMachineIdStartTime(machine.getMachineId(), moveLogs.get(0).getStartTime(), null);
        } else {
            rideLogs = rideLogService.getMachineIdStartTime(machine.getMachineId(), null, nowTime);
        }
        remark.append("上次挪车后产生有效订单：");
        if (checkedCondition.contains("1")) {
            // 上次调度后产生有效订单
            if (CollectionUtils.isEmpty(rideLogs)) {
                remark.append("无效；");
                failedConditionsCount++;
            }else {
                remark.append("有效；");
            }
        }else {
            remark.append("关闭；");
        }
        //上次挪车后骑行xx米
        remark.append("上次挪车后骑行距离：");
        if (checkedCondition.contains("2") && Objects.nonNull(moveConfig.getLastMoveRideDistance())) {
            double sumMileage = CollectionUtils.isNotEmpty(rideLogs) ? (rideLogs.stream().mapToDouble(RideLog::getMileage).sum() * 1000) : 0L;
            remark.append("配置：").append(moveConfig.getLastMoveRideDistance()).append("米").append("，实际：").append(sumMileage).append("米");
            if (sumMileage < Double.valueOf(moveConfig.getLastMoveRideDistance())){
                remark.append("(无效)；");
                failedConditionsCount++;
            }else {
                remark.append("(有效)；");
            }
        }else {
            remark.append("关闭；");
        }
        //上次挪车后经过xx分钟
        remark.append("上次挪车后配置间隔时间：");
        Integer lastMoveIntervalTime = moveConfig.getLastMoveIntervalTime();
        if (checkedCondition.contains("3") && Objects.nonNull(lastMoveIntervalTime)) {
            remark.append("配置：").append(lastMoveIntervalTime).append("分钟");
            List<MoveLog> moveLogList = this.getByMachineIdTime(machine.getMachineId(), DateTimeUtil.getMinsAgo(lastMoveIntervalTime));
            if (CollectionUtils.isNotEmpty(moveLogList) && lastMoveIntervalTime > 0) {
                remark.append("(无效)；");
                failedConditionsCount++;
            }else{
                remark.append("(有效)；");
            }
        }else {
            remark.append("关闭，");
        }
        boolean finalResult;
        if (matchOne) {
            finalResult = checkedCondition.size() != failedConditionsCount;
        } else {
            finalResult = failedConditionsCount == 0;
        }
        moveLog.setIsValid(finalResult);
        log.info("前置挪车方法内moveLog：{}", JSON.toJSONString(moveLog));
        if (StringUtils.isNotBlank(remark)) {
            remark.append("[前置条件]。");
        }
        log.info("前置条件挪车最终结果：" + remark.toString());
        return remark.toString();
    }

    /**
     * 根据时间查询
     *
     * @param machineId
     * @param time
     * @return
     */
    private List<MoveLog> getByMachineIdTime(Integer machineId, String time) {
        Map<String, Object> map = new HashMap<>();
        map.put("machineId", machineId);
        map.put("time", time);
        return moveLogDao.getByMachineIdTime(map);
    }


    /**
     * @description: 添加挪车记录
     * @author: mo.shanyong
     * @date: 2025/5/16 14:36
     * @param: moveLog
     * @param: moveConfig
     * @param: machine
     * @param: accountUser
     * @param: newTime
     * @param: machineStatus
     * @param: parkPointId
     * @param: parkPoint
     */

    private void addMoveLog(MoveLog moveLog,MoveConfig moveConfig,Machine machine,
                            AccountUser accountUser,String newTime){
        Boolean moveLogIsValid = moveLog.getIsValid();
        Integer state = WorkOrderConstant.state_WC;
        // 判断订单时间
        if (moveConfig.getRideTime() != null && moveConfig.getRideTime() != 0) {
            state = WorkOrderConstant.state_SHZ;
        }
        if (!state.equals(WorkOrderConstant.state_SHZ)) {
            state = WorkOrderConstant.state_WC;
        }
        insert(moveLog);
        /**是否存在工单信息*/
        String workOrderId = this.endWork(accountUser, machine, moveLog, state);

        /**订单条件缓存*/
        if (state.equals(WorkOrderConstant.state_SHZ) && moveLogIsValid) {
            PowerChangeRedis powerChangeRedis = new PowerChangeRedis();
            powerChangeRedis.setPowerChangeId(moveLog.getMoveLogId());
            powerChangeRedis.setWorkOrderId(workOrderId);
            powerChangeRedis.setRideTime(moveConfig.getRideTime());
            powerChangeRedis.setTime(newTime);

            List<PowerChangeRedis> powerChangeList = new LinkedList<>();
            /**判断是否存在审核中*/
            String powerChangeRedisList = redisService.get(RedisConstant.REDIS_TER_MOVE_CHANGE_RIDE + machine.getMachineNO());
            if (powerChangeRedisList != null) {
                List<PowerChangeRedis> powerChangeLogs = new LinkedList<>();
                try {
                    powerChangeLogs = JSON.parseArray(powerChangeRedisList, PowerChangeRedis.class);
                } catch (JSONException e) {
                    redisService.del(RedisConstant.REDIS_TER_MOVE_CHANGE_RIDE + machine.getMachineNO());
                }

                if (CollUtil.isNotEmpty(powerChangeLogs)) {
                    powerChangeList.addAll(powerChangeLogs);
                }
            }
            powerChangeList.add(powerChangeRedis);

            /**订单判断缓存*/
            redisService.add(RedisConstant.REDIS_TER_MOVE_CHANGE_RIDE + machine.getMachineNO(), JSONObject.toJSONString(powerChangeList), (3600 * moveConfig.getRideTime()) + 3600);
            /**二级缓存*/
            redisService.set(RedisConstant.REDIS_TER_BIKE_MOVE_CHANGE_RIDE_MAP, machine.getMachineNO(), String.valueOf(System.currentTimeMillis()));
        }

        /**删除redis记录*/
        redisService.del(RedisConstant.REDIS_TER_BIKE_MOVE + machine.getMachineNO());
    }

    /**
     * @description: 如果同一辆车在配置的产生订单时间内又发生了挪车，则要把之前的挪车记录置为失效
     * @author: mo.shanyong
     * @date: 2025/5/29 10:21
     * @param: machineNO
     * @param: moveLogId
     */
    private void checkMachineLastMove(String machineNO,Integer moveLogId,MoveConfig moveConfig,String nowTime){
        /** 查询当前挪车工单的记录 */
        Map<String, String> machineMoveMap = redisService.getAll(RedisConstant.REDIS_TER_BIKE_MOVE_CHANGE_RIDE_MAP);
        if (!machineMoveMap.containsKey(machineNO)){
            return;
        }
        String redis = redisService.get(RedisConstant.REDIS_TER_MOVE_CHANGE_RIDE + machineNO);
        Machine machine = machineService.getByMachineNO(machineNO);
        if (StringUtils.isBlank(redis)){
            /**删除缓存*/
            this.delMoveCache(machine,machineNO);
            return;
        }
        List<PowerChangeRedis> powerChangeRedisList = new LinkedList<>();
        try {
            powerChangeRedisList = JSON.parseArray(redis, PowerChangeRedis.class);
        } catch (SerializationException e) {
            redisService.del(RedisConstant.REDIS_TER_MOVE_CHANGE_RIDE + machineNO);
        }
        if (CollUtil.isNotEmpty(powerChangeRedisList)) {
            /**循环遍历多个审核中记录*/
            Iterator<PowerChangeRedis> it = powerChangeRedisList.iterator();
            while (it.hasNext()) {
                PowerChangeRedis powerChangeRedis = it.next();
                //排除当前的挪车记录和在当前挪车记录之后的挪车记录
                if (Objects.equals(powerChangeRedis.getPowerChangeId(),moveLogId) ||
                        DateTimeUtil.getLocalDateTimeByTimeStr(nowTime).isBefore(DateTimeUtil.getLocalDateTimeByTimeStr(powerChangeRedis.getTime()))){
                    continue;
                }
                // 判断审核中调度记录是否符合规定时间内未产生有效骑行订单条件，符合就置为失效
                this.checkMoveLog(powerChangeRedis,machine);
                /**审核后删除*/
                it.remove();
            }
        }

        /**判断是否为空，删除缓存*/
        if (CollUtil.isNotEmpty(powerChangeRedisList)) {
            //找到最大的时间
            Integer rideTime = powerChangeRedisList.stream().max(Comparator.comparing(PowerChangeRedis::getTime)).map(PowerChangeRedis::getRideTime).orElse(moveConfig.getRideTime());
            redisService.add(RedisConstant.REDIS_TER_MOVE_CHANGE_RIDE + machineNO, JSONObject.toJSONString(powerChangeRedisList), (3600 * rideTime) + 3600);
        } else {
            /**删除缓存*/
            this.delMoveCache(machine,machineNO);
        }

    }
    /**
     * @description: 检查挪车记录是否有效
     * @author: mo.shanyong
     * @date: 2025/5/29 10:28
     * @param: powerChangeRedis
     * @param: machine
     */
    public void checkMoveLog(PowerChangeRedis powerChangeRedis,Machine machine){
        MoveLog moveLog = moveLogDao.getById(powerChangeRedis.getPowerChangeId());
        String finishTime = StringUtils.isBlank(powerChangeRedis.getTime()) ? moveLog.getEndTime() : powerChangeRedis.getTime();
        Date afterLatestTime = rideLogService.getAfterLatest(finishTime, machine.getMachineId());
        if (afterLatestTime == null ||
                ChronoUnit.SECONDS.between(DateTimeUtil.getLocalDateTimeByTimeStr(DateTimeUtil.getDateTimeStr(afterLatestTime)),
                        DateTimeUtil.getLocalDateTimeByTimeStr(finishTime)) > (powerChangeRedis.getRideTime() * 3600)) {//无效
            this.updateMoveLogAndWorkOrder(moveLog,powerChangeRedis,WorkOrderConstant.isValid);
        } else{//有效，如果之前的条件就已经无效了，那产生订单的配置就不需要判断了
            this.updateMoveLogAndWorkOrder(moveLog,powerChangeRedis,WorkOrderConstant.valid);
        }
    }


    /**
     * @description: 删除挪车缓存
     * @author: mo.shanyong
     * @date: 2025/5/16 17:04
     * @param: machine
     * @param: machineNO
     */
    private void delMoveCache(Machine machine,String machineNO){
        redisService.del(RedisConstant.REDIS_TER_MOVE_CHANGE_RIDE + machineNO);
        log.info("挪车定时任务删除不存在调度缓存：" +machineNO + ";");
        redisService.delToList(RedisConstant.REDIS_TER_BIKE_MOVE_CHANGE_RIDE_MAP, machineNO);
        log.info("挪车定时任务删除不存在二级缓存：" + machineNO + ";");
        if (Objects.nonNull(machine)) {
            String accountDispatch = RedisConstant.REDIS_BATCH_MOVE_AREA + machine.getAccountId();
            redisService.delToList(accountDispatch, machine.getUserCode());
        }
    }

    /**
     * @description: 更新挪车记录、工单的状态
     * @author: mo.shanyong
     * @date: 2025/5/16 17:04
     * @param: moveLog
     * @param: powerChangeRedis
     * @param: isValid
     */
    private void updateMoveLogAndWorkOrder(MoveLog moveLog,PowerChangeRedis powerChangeRedis,Integer isValid){
        String remark = moveLog.getRemark() + "；" + powerChangeRedis.getRideTime() + "小时" + (Objects.equals(isValid,WorkOrderConstant.isValid) ? WorkOrderConstant.sys_rideTime_Valid : WorkOrderConstant.sys_rideTime_isValid);
        WorkOrder workOrderDB = workOrderService.getByWorkOrderId(powerChangeRedis.getWorkOrderId());
        /**判断存储是否是工单*/
        if (workOrderDB != null) {
            WorkOrder workOrder = new WorkOrder();
            workOrder.setWorkOrderId(powerChangeRedis.getWorkOrderId());
            workOrder.setState(WorkOrderConstant.state_WC);
            workOrder.setBusinessNO(powerChangeRedis.getPowerChangeId());
            workOrder.setIsValid(isValid);
            workOrder.setRemark(remark);
            workOrderService.update(workOrder);
        }

        log.info("更新挪车日志，挪车日志id：{},valid：{}", powerChangeRedis.getPowerChangeId(), isValid);
        this.audit(powerChangeRedis.getPowerChangeId(), Objects.equals(isValid,WorkOrderConstant.valid), remark);
    }

    /**
     * @description: 检查是否在站内
     * @author: mo.shanyong
     * @date: 2025/5/30 17:38
     * @param: parkPointId
     * @param: machineStatus
     * @param: moveConfig
     * @return: java.lang.Integer
     */
    private Integer checkInPark(Integer parkPointId,MachineStatus machineStatus,MoveConfig moveConfig){
        //校准定位
        Point point = new Point(machineStatus.getLon(), machineStatus.getLat());
        calibrateService.commonCalibrate(point, MapConstant.MAP_ORI, SysConstant.GOOGLE);
        Integer inside = null;
        ParkPoint parkPoint1 = dataService.getParkPoint(parkPointId);
        ParkPoint parkPoint2 = parkPointService.checkInParkPointNew(moveConfig.getAccountId(), point, 50, parkPoint1.getAllowRange());
        if (Objects.nonNull(parkPoint2) && Objects.equals(parkPoint1.getParkPointId(),parkPoint2.getParkPointId())) {
            inside = 1;
        } else {
            inside = 0;
        }
        log.info("machineStatus:{},parkPoint1:{},parkPoint2:{},moveConfig:{},inside:{}",
                JSON.toJSONString(machineStatus),JSON.toJSONString(parkPoint1),JSON.toJSONString(parkPoint2),JSON.toJSONString(moveConfig),inside);
        return inside;
    }




}